package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.dto.CollectionChipInfoPageDTO;
import com.sc.nft.dto.CollectionChipInfoRecordPageDTO;
import com.sc.nft.entity.ActivityAward;
import com.sc.nft.entity.CollectionChipInfo;
import com.sc.nft.entity.vo.CollectionChipCountVO;
import com.sc.nft.entity.vo.CollectionChipInfoPageVO;
import com.sc.nft.entity.vo.CollectionChipInfoRecordPageVO;
import com.sc.nft.mapper.ActivityAwardMapper;
import com.sc.nft.mapper.CollectionChipInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
public class CollectionChipInfoDao extends ServiceImpl<CollectionChipInfoMapper, CollectionChipInfo> {


    /**
     * 芯片程序 数量查询
     * @param collectionChipId
     * @return
     */
    public CollectionChipCountVO getChipInfoCount(Long collectionChipId) {
        return baseMapper.getChipInfoCount(collectionChipId);
    }

    public void saveList(List<CollectionChipInfo> collectionChipInfoList) {
         baseMapper.saveList(collectionChipInfoList);
    }

    public Page<CollectionChipInfoPageVO> pageList(CollectionChipInfoPageDTO pageDTO) {
        return baseMapper.pageList(pageDTO.toMp() ,pageDTO);
    }

    public IPage<CollectionChipInfoRecordPageVO> recordPage(CollectionChipInfoRecordPageDTO pageDTO) {
        return baseMapper.recordPage(pageDTO.toMp(),pageDTO);
    }

    public Boolean updateReceiveStatusAndUserCollectionId(Long id, Integer status,Long userCollectionId) {
        LambdaUpdateWrapper<CollectionChipInfo> lambdaUpdateWrapper = new LambdaUpdateWrapper();
        lambdaUpdateWrapper.eq(CollectionChipInfo::getId,id);
        lambdaUpdateWrapper.set(CollectionChipInfo::getReceiveStatus,status);
        lambdaUpdateWrapper.set(CollectionChipInfo::getUserCollectionId,userCollectionId);
        return update(lambdaUpdateWrapper);
    }

    public Boolean updateWriteStatus(List<Long> idList, Boolean status) {
        LambdaUpdateWrapper<CollectionChipInfo> lambdaUpdateWrapper = new LambdaUpdateWrapper();
        lambdaUpdateWrapper.in(CollectionChipInfo::getId,idList);
        lambdaUpdateWrapper.set(CollectionChipInfo::getWriteStatus,status);
        return update(lambdaUpdateWrapper);
    }

    public List<CollectionChipInfo> export(CollectionChipInfoPageDTO pageDTO) {
        return baseMapper.export(pageDTO);
    }

    public List<CollectionChipInfo> getByChipId(Long chipId) {
        LambdaQueryWrapper<CollectionChipInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CollectionChipInfo::getCollectionChipId,chipId);
        return list(queryWrapper);
    }
}
